package com.ruoyi.inspection.domain.receiveVo;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.ruoyi.common.constant.GlobalConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.inspection.constant.InspectionConstant;
import com.ruoyi.system.domain.AppCreateJobBill;
import lombok.Data;

import java.io.Serializable;
import java.util.Date;
import java.util.UUID;

/**
 * 上报特殊作业票证信息
 */
@Data
public class ReceiveJobAttachment implements Serializable {
    //企业编码
    private String companyCode;
    // 特殊作业ID
    private String id;
    // 附件名称, xxx动火作业.pdf
    private String fileName;
    // "application/pdf" 附件类型，必填
    private String fileType;
    // 附件内容，用base64 编码后传输
    private String attachment;
    // 删除状态 0有效 1删除
    private String deleted;
    private String createBy;
    private String createDate;
    private String updateBy;
    private String updateDate;


    /**
     * 构建作业票对象
     * @param jobBill
     * @return
     */
    public static ReceiveJobAttachment convertReceiveJobAttachment(AppCreateJobBill jobBill) {
        String workOrderId = jobBill.getGovernId();
        if (StringUtils.isEmpty(workOrderId)) {
            return null;
        }

        String governAttachId = jobBill.getGovernAttachId();
        governAttachId = StringUtils.isEmpty(governAttachId) ? UUID.randomUUID().toString() : governAttachId;
        Date updateDate = jobBill.getModifyDate()==null ? jobBill.getCreatedDate() : jobBill.getModifyDate();
        String updateDateStr = DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", updateDate);

        ReceiveJobAttachment attachment = new ReceiveJobAttachment();
        attachment.setId(governAttachId);
        attachment.setCompanyCode(GlobalConstants.COMPANY_CODE);
        attachment.setDeleted("0");
        attachment.setCreateDate(DateUtils.parseDateToStr("yyyy-MM-dd HH:mm:ss", jobBill.getCreatedDate()));
        attachment.setCreateBy(StringUtils.isEmpty(jobBill.getCreatedBy()) ? "admin" : jobBill.getCreatedBy());
        attachment.setUpdateDate(updateDateStr);
        attachment.setUpdateBy(jobBill.getModifyBy()==null ? "admin" : jobBill.getModifyBy());

        jobBill.setGovernAttachId(governAttachId);
        return attachment;
    }

}
